package cn.king.springframework.bean.test.common;

import cn.king.springframework.bean.test.UserService;
import cn.king.springframework.beans.BeanException;
import cn.king.springframework.beans.factory.config.BeanPostProcessor;

public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialzation(Object bean, String beanName) throws BeanException {
        if("userService".equals(beanName)){
            UserService userService = (UserService) bean;
            userService.setLocation("改为:北京");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialzation(Object bean, String beanName) throws BeanException {
//        if("userService".equals(beanName)){
//            UserService userService = (UserService) bean;
//            userService.setLocation("改为:武汉");
//        }
        return bean;
    }
}
